package Demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-03
 * Time: 17:45
 */
public class Computer {
    public void powerOn() {
        System.out.println("打开电脑");
    }

    public void powerOff() {
        System.out.println("关闭电脑");
    }

    public void useDevice(IUSB usb) {
        usb.Open();
        if (usb instanceof Mouse) {
//            ((Mouse) usb).click();
            Mouse mouse = (Mouse) usb;
            mouse.click();

        }
        if (usb instanceof Keyboard) {
//            ((Keyboard) usb).input();
            Keyboard keyboard = (Keyboard) usb;
            keyboard.input();
        }
        usb.Close();
    }

    public static void main(String[] args) {
        Computer myComputer = new Computer();

        myComputer.powerOn();

        myComputer.useDevice(new Keyboard());
        myComputer.useDevice(new Mouse());


        myComputer.powerOff();
    }
}

